#include <stdio.h>

//二分查找递归实现

int binary_search_recursive(int arr[],int left,int right,int target)
{
   if(left <= right){
    int mid = left + (right -  left) / 2;
   

    if(arr[mid] == target){
        return mid;
    }

    if(arr[mid] < target){
        return binary_search_recursive(arr,mid + 1,right,target);//右半部分
    }

    return binary_search_recursive(arr,left,mid - 1,target);//zuo半部分
    return -1;//没有找到
}
}

int main()
{
    int arr[] = {1, 3, 5, 7, 9, 11};
    size_t sz = sizeof(arr)/sizeof(arr[0]);
    int target = 9;
    int result = binary_search_recursive(arr,0,sz - 1,target); 
    (result == -1) ? (printf("未找到目标数\n")) : (printf("目标数的下标是：%d\n",result));
    return 0;
}